package cn.izeno.wx

import cn.izeno.wx.models.component.InnerList
import io.reactivex.rxjava3.core.Observable

fun <T> Observable<out InnerList<T>>.zzBody(): List<T> {
  var result: List<T> = emptyList()
  var error: Throwable? = null
  this.map { it.data }.subscribe({
    result = it
  }, { error = it })

  if (error != null) throw error!!

  return result
}

fun <T> Observable<T>.zzBody(): T {
  var result: T? = null
  var error: Throwable? = null
  this.subscribe({
    result = it
  }, { error = it })

  if (error != null) throw error!!

  return result!!
}
